package com.eeepay.eeepay_v2.activity;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.eeepay.eeepay_v2.R;
import com.eeepay.eeepay_v2.adapter.MerTypeAdapter;
import com.eeepay.eeepay_v2.model.MccType;
import com.eeepay.eeepay_v2.util.Constant;
import com.eeepay.eeepay_v2.util.DataUtils;
import com.eeepay.eeepay_v2.util.SPUtils;
import com.eeepay.v2_library.ui.ABBaseActivity;

import java.util.List;
import java.util.Map;

/**
 * Created by Ching on 2016/4/12.
 * 简单的数组列表展示
 * 商户类别
 */
public class SimpleListActivity extends ABBaseActivity implements AdapterView.OnItemClickListener {

    private ListView listView;

    private String[] merType;
    Map<String, List<MccType>> mccMap;
    private MerTypeAdapter adapter;
    private List<MccType> datas;
    private Intent intent;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_simple_list;
    }

    @Override
    protected void initWidget() {
        listView = getViewById(R.id.lv_simple_list);
    }

    @Override
    protected void eventOnClick() {
        datas = SPUtils.getList(Constant.KEY.MERTYPE);
        if (datas != null && datas.size() > 0) {
            adapter = new MerTypeAdapter(this,true);
            adapter.addAll(datas);
            listView.setAdapter(adapter);
            listView.setOnItemClickListener(this);
//            merType = new String[datas.size()];
//            for (int i = 0; i < datas.size(); i++) {
//                Log.d("merType", "  merType " + datas.get(i).getSysName());
//            }

        }

    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        DataUtils.getInstance().setMerType(datas.get(position).getSysName()
                ,datas.get(position).getSysValue());
        intent = new Intent();
        intent.putExtra(Constant.KEY.MERTYPE,datas.get(position).getSysName());
        intent.setClass(this,MccActivity.class);
        startActivity(intent);
        finish();
    }

//    {"民生类", "餐娱类", "批发类", "一般类", "房车类", "其他"}
}
